package microcredit.gui.editor.member;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import microcredit.gui.base.EnumComboBox;
import microcredit.gui.base.EnumComboBoxModel;
import microcredit.gui.editor.AbstractEditorForm;
import microcredit.gui.util.FixedLengthDocument;
import microcredit.gui.util.MDatePicker;
import microcredit.gui.util.NumericTextField;
import microcredit.gui.util.UIUtil;
import microcredit.model.Member;
import microcredit.model.MemberGroup;
import microcredit.model.MemberStatusHistory;
import microcredit.model.ValidationException;
import microcredit.model.bo.BOMemberGroup;
import microcredit.model.domain.Gender;
import microcredit.model.domain.HIVStatus;
import microcredit.model.domain.LevelOfEducation;
import microcredit.model.domain.MartialStatus;
import microcredit.model.domain.MemberInactiveReason;
import microcredit.model.domain.Status;
import net.miginfocom.swing.MigLayout;

public class MemberGeneralForm extends AbstractEditorForm<Member> {

	private JPanel memberPanel;
	private JLabel firstNameLabel;
	private JTextField firstNameTextField;
	private JLabel lastNameLabel;
	private JTextField lastNameTextfield;
	private JLabel middleNameLabel;
	private JLabel genderLabel;
	private JTextField middleNameTextfield;
	private JCheckBox activechckbx;
	private GenderComboBox genderComboBox;
	private JLabel birthDateLabel;
	private JLabel levelOfEducationLabel;
	private LevelOfEducationComboBox levelOfEducationComboBox;
	private JTextField numberOfPeopleTextfield;
	private JLabel residenceLabel;
	private JScrollPane residenceScrollPane;
	private JTextArea residenceTextArea;
	private JLabel numberOfPeopleLabel;
	private JLabel numberOfChildrenLabel;
	private JTextField numberOfChildrenTextfield;
	private JLabel groupLabel;
	private MemberGroupComboBox groupComboBox;
	private JLabel lblAdditionalInformation;
	private JScrollPane scrollPane;
	private JTextArea descriptionTextArea;
	private JLabel inactiveReasonLabel;
	private JLabel inactiveReasonTextLabel;
	private JScrollPane inactiveReasonTextScrollPane;
	private JTextArea inactiveReasonTextArea;
	private MemberInactiveReasonCombobox inactiveReasonCombobox;
	private JSeparator inactiveSeparator;
	private MDatePicker birtdatePanel;
	private JLabel hivStatusLabel;
	private HIVStatusComboBox hivStatusComboBox;
	private JLabel martialStatusLabel;
	private MartialStatusComboBox martialStatusComboBox;
	
	public MemberGeneralForm() {
		initialize();
		setTitle("General");
		
		UIUtil.setMandatoryFields(this, Member.FIRST_NAME, Member.LAST_NAME,
				Member.GENDER, Member.BIRTH_DATE, Member.NUMBER_CARE_FOR,
				Member.NUMBER_CHILDREN_IN_SCHOOL, Member.INACTIVE_REASON, Member.HIV_STATUS);
	}
	
	@Override
	public void focusDefault() {
		getFirstNameTextField().requestFocus();
	}

	public Member receive(Member m) {
		m.setFirstName(getFirstNameTextField().getText());
		m.setLastName(getLastNameTextfield().getText());
		m.setMiddleName(getMiddleNameTextfield().getText());
		m.setResidence(getResidenceTextArea().getText());
		m.setGroup(getGroupComboBox().getValue());
		
		m.setGender(getGenderComboBox().getValue());
	
		m.setMartialStatus(getMartialStatusComboBox().getValue());
		m.setHivStatus(getHivStatusComboBox().getValue());
		m.setStatus(getActivechckbx().isSelected() ? Status.A : Status.I);
		
		m.setLevelOfEducation(getLevelOfEducationComboBox().getValue());
		try {
			if (getNumberOfPeopleTextfield().getText() == null || getNumberOfPeopleTextfield().getText().isEmpty()) {
				m.setNumberCareFor(null);
			} else {
				m.setNumberCareFor(Short.parseShort(getNumberOfPeopleTextfield().getText()));
			}
		} catch (NumberFormatException e1) {
			getNumberOfPeopleTextfield().requestFocus();
			getNumberOfPeopleTextfield().selectAll();
			throw new ValidationException("Invalid number of people entered.", Member.NUMBER_CARE_FOR);
		}
		try {
			if (getNumberOfChildrenTextfield().getText() == null || getNumberOfChildrenTextfield().getText().isEmpty()) {
				m.setNumberChildrenInSchool(null);
			} else {
				m.setNumberChildrenInSchool(Short.parseShort(getNumberOfChildrenTextfield().getText()));
			}
		} catch (NumberFormatException e) {
			getNumberOfChildrenTextfield().requestFocus();
			getNumberOfChildrenTextfield().selectAll();
			throw new ValidationException("Invalid number of children entered.", Member.NUMBER_CHILDREN_IN_SCHOOL);
		}
		m.setBirthDate(getBirtdatePanel().getDate());
		m.setDescription(getDescriptionTextArea().getText());
		
		// remove all status histories which are not saved
		if (m.getMemberStatusHistories() != null) {
			for (Iterator<MemberStatusHistory> iterator = m.getMemberStatusHistories().iterator(); iterator.hasNext();) {
				MemberStatusHistory subHistory = iterator.next();
				if (subHistory.getSequenceID() == null) {
					iterator.remove();
				}
			}
		}
		
		MemberStatusHistory history = m.getLastStatusHistory();
		if (history != null 
				&& history.getSequenceID() != null
				&& !history.getStatus().equals(m.getStatus())) {
			if (history.getSequenceID() == null) {
				m.getMemberStatusHistories().remove(history);
			}
			history = null;
		}
		
		if (history == null) {
			history = new MemberStatusHistory();
			history.setMember(m);
			if (m.getMemberStatusHistories() == null) {
				m.setMemberStatusHistories(new ArrayList<MemberStatusHistory>());
			}
			m.getMemberStatusHistories().add(history);
		}
		history.setStatus(getActivechckbx().isSelected() ? Status.A : Status.I);
		if (history.getStatus() == Status.I) {
			history.setReason(getInactiveReasonCombobox().getValue());
			history.setReasonText(getInactiveReasonTextArea().getText());
		} else {
			history.setReason(null);
			history.setReasonText(null);
		}
		return m;
	}

	public void apply(Member m) {
		getFirstNameTextField().setText(m.getFirstName());
		getLastNameTextfield().setText(m.getLastName());
		getMiddleNameTextfield().setText(m.getMiddleName());
		getResidenceTextArea().setText(m.getResidence());
		getGroupComboBox().setValue(m.getGroup());
		
		getBirtdatePanel().setDate(m.getBirthDate());
		getGenderComboBox().setValue(m.getGender());
		
		getMartialStatusComboBox().setValue(m.getMartialStatus());
		getHivStatusComboBox().setValue(m.getHivStatus());
		if (m.getStatus() == null
				|| m.getStatus() == Status.A) {
			getActivechckbx().setSelected(true);
		} else {
			getActivechckbx().setSelected(false);
		}
		
		getLevelOfEducationComboBox().setValue(m.getLevelOfEducation());
		
		if (m.getNumberChildrenInSchool() != null) {
			getNumberOfChildrenTextfield().setText(String.valueOf(m.getNumberChildrenInSchool()));
		} else {
			getNumberOfChildrenTextfield().setText("");
		}
		if (m.getNumberCareFor() != null) {
			getNumberOfPeopleTextfield().setText(String.valueOf(m.getNumberCareFor()));
		} else {
			getNumberOfPeopleTextfield().setText("");
		}
		
		getDescriptionTextArea().setText(m.getDescription());
		
		MemberStatusHistory history = m.getLastStatusHistory();
		if (history != null) {
			getInactiveReasonCombobox().setValue(history.getReason());
			getInactiveReasonTextArea().setText(history.getReasonText());
		}
	}
	
	private void setInactiveDataVisible(boolean visible) {
		getInactiveReasonCombobox().setVisible(visible);
		getInactiveReasonLabel().setVisible(visible);
		getInactiveReasonTextArea().setVisible(visible);
		getInactiveReasonTextLabel().setVisible(visible);
		getInactiveReasonTextScrollPane().setVisible(visible);
		getInactiveSeparator().setVisible(visible);
		revalidate();
	}
	
	
	private void initialize() {
		setLayout(new MigLayout("", "[grow]", "[]0[grow]"));
		add(getMemberPanel(), "cell 0 1,grow");
	}

	private JPanel getMemberPanel() {
		if (memberPanel == null) {
			memberPanel = new JPanel();
			memberPanel.setLayout(new MigLayout("hidemode 3", "[][grow][right][grow][]", "[][][top][][][][][][top][][][][30px,bottom][grow]"));
			memberPanel.setName("mainPanel");
			memberPanel.add(getInactiveReasonLabel(), "cell 0 1,alignx trailing");
			memberPanel.add(getInactiveReasonCombobox(), "cell 1 1 3 1,growx");
			memberPanel.add(getInactiveReasonTextLabel(), "cell 0 2,alignx right");
			memberPanel.add(getInactiveReasonTextScrollPane(), "cell 1 2 3 1,grow");
			memberPanel.add(getInactiveSeparator(), "cell 0 3 4 1,grow");
			memberPanel.add(getBirtdatePanel(), "cell 1 8,grow");
			memberPanel.add(getHivStatusLabel(), "cell 0 10,alignx trailing");
			memberPanel.add(getHivStatusComboBox(), "cell 1 10,growx");
			memberPanel.add(getMartialStatusLabel(), "cell 2 10,alignx trailing");
			memberPanel.add(getMartialStatusComboBox(), "cell 3 10,growx");
			getMemberPanel().add(getLabel_8(), "flowx,cell 0 11 2 1");
			getMemberPanel().add(getNumberOfPeopleTextfield(), "cell 0 11 2 1,growx");
			getMemberPanel().add(getNumberOfChildrenLabel(), "flowx,cell 2 11 2 1,alignx trailing");
			getMemberPanel().add(getNumberOfChildrenTextfield(), "cell 2 11 2 1,growx");
			getMemberPanel().add(getActivechckbx(), "cell 1 0 3 1");
			getMemberPanel().add(getFirstNameLabel(), "cell 0 5,alignx trailing");
			getMemberPanel().add(getFirstNameTextField(), "cell 1 5,growx");
			getMemberPanel().add(getMiddleNameLabel(), "cell 2 5,alignx trailing");
			getMemberPanel().add(getMiddleNameTextfield(), "cell 3 5,growx");
			getMemberPanel().add(getLastNameLabel(), "cell 0 6,alignx trailing");
			getMemberPanel().add(getLastNameTextfield(), "cell 1 6,growx");
			getMemberPanel().add(getLabel_7(), "cell 2 7");
			getMemberPanel().add(getResidenceScrollPane(), "cell 3 7 1 3,grow");
			getMemberPanel().add(getGenderLabel(), "cell 0 7,alignx trailing");
			getMemberPanel().add(getGenderComboBox(), "cell 1 7,growx");
			getMemberPanel().add(getLabel_4(), "cell 0 8,alignx trailing");
			getMemberPanel().add(getLabel_5(), "cell 0 9,alignx right");
			getMemberPanel().add(getLevelOfEducationComboBox(), "cell 1 9,growx");
			getMemberPanel().add(getGroupLabel(), "cell 2 6,alignx trailing");
			getMemberPanel().add(getGroupComboBox(), "cell 3 6,growx");
			memberPanel.add(getLblAdditionalInformation(), "cell 0 12 4 1");
			memberPanel.add(getScrollPane(), "cell 0 13 4 1,grow");
		}
		return memberPanel;
	}
	private JLabel getFirstNameLabel() {
		if (firstNameLabel == null) {
			firstNameLabel = new JLabel("First name:");
			firstNameLabel.setLabelFor(getFirstNameTextField());
			firstNameLabel.setName("firstNameLabel");
		}
		return firstNameLabel;
	}
	private JTextField getFirstNameTextField() {
		if (firstNameTextField == null) {
			firstNameTextField = new JTextField();
			firstNameTextField.setName(Member.FIRST_NAME);
			firstNameTextField.setColumns(15);
			firstNameTextField.setDocument(new FixedLengthDocument(255));
		}
		return firstNameTextField;
	}
	private JLabel getLastNameLabel() {
		if (lastNameLabel == null) {
			lastNameLabel = new JLabel("Last name:");
			lastNameLabel.setLabelFor(getLastNameTextfield());
			lastNameLabel.setName("lastNameLabel");
		}
		return lastNameLabel;
	}
	private JTextField getLastNameTextfield() {
		if (lastNameTextfield == null) {
			lastNameTextfield = new JTextField();
			lastNameTextfield.setName(Member.LAST_NAME);
			lastNameTextfield.setColumns(15);
			lastNameTextfield.setDocument(new FixedLengthDocument(255));
		}
		return lastNameTextfield;
	}
	private JLabel getMiddleNameLabel() {
		if (middleNameLabel == null) {
			middleNameLabel = new JLabel("Middle name:");
			middleNameLabel.setLabelFor(getMiddleNameTextfield());
			middleNameLabel.setName("middleNameLabel");
		}
		return middleNameLabel;
	}
	private JLabel getGenderLabel() {
		if (genderLabel == null) {
			genderLabel = new JLabel("Gender:");
			genderLabel.setLabelFor(getGenderComboBox());
			genderLabel.setName("genderLabel");
		}
		return genderLabel;
	}
	private JTextField getMiddleNameTextfield() {
		if (middleNameTextfield == null) {
			middleNameTextfield = new JTextField();
			middleNameTextfield.setName("middleName");
			middleNameTextfield.setColumns(15);
			middleNameTextfield.setDocument(new FixedLengthDocument(255));
		}
		return middleNameTextfield;
	}
	private JCheckBox getActivechckbx() {
		if (activechckbx == null) {
			activechckbx = new JCheckBox("Active member");
			activechckbx.addChangeListener(new ChangeListener() {
				public void stateChanged(ChangeEvent e) {
					setInactiveDataVisible(!getActivechckbx().isSelected());
				}
			});
			activechckbx.setSelected(true);
			activechckbx.setName("activechckbx");
		}
		return activechckbx;
	}
	private GenderComboBox getGenderComboBox() {
		if (genderComboBox == null) {
			genderComboBox = new GenderComboBox();
			genderComboBox.setModel(new EnumComboBoxModel(Gender.values(), "<< Please select >>"));
			genderComboBox.setName(Member.GENDER);
			genderComboBox.enableAutocompletion();
		}
		return genderComboBox;
	}
	private JLabel getLabel_4() {
		if (birthDateLabel == null) {
			birthDateLabel = new JLabel("Birth date:");
			birthDateLabel.setLabelFor(getBirtdatePanel());
			birthDateLabel.setName("birthDateLabel");
			birthDateLabel.setName("label");
		}
		return birthDateLabel;
	}
	private JLabel getLabel_5() {
		if (levelOfEducationLabel == null) {
			levelOfEducationLabel = new JLabel("Level of education:");
			levelOfEducationLabel.setLabelFor(getLevelOfEducationComboBox());
			levelOfEducationLabel.setName("levelOfEducationLabel");
			levelOfEducationLabel.setName("label");
		}
		return levelOfEducationLabel;
	}
	private LevelOfEducationComboBox getLevelOfEducationComboBox() {
		if (levelOfEducationComboBox == null) {
			levelOfEducationComboBox = new LevelOfEducationComboBox();
			levelOfEducationComboBox.setModel(new EnumComboBoxModel(LevelOfEducation.values(), "<< Please select >>"));
			levelOfEducationComboBox.setName(Member.LEVEL_OF_EDUCATION);
			levelOfEducationComboBox.enableAutocompletion();
		}
		return levelOfEducationComboBox;
	}
	private JTextField getNumberOfPeopleTextfield() {
		if (numberOfPeopleTextfield == null) {
			numberOfPeopleTextfield = new NumericTextField(10, (DecimalFormat)DecimalFormat.getIntegerInstance());
			numberOfPeopleTextfield.setName(Member.NUMBER_CARE_FOR);
		}
		return numberOfPeopleTextfield;
	}
	private JLabel getLabel_7() {
		if (residenceLabel == null) {
			residenceLabel = new JLabel("Residence:");
			residenceLabel.setLabelFor(getResidenceTextArea());
			residenceLabel.setName("residenceLabel");
		}
		return residenceLabel;
	}
	private JScrollPane getResidenceScrollPane() {
		if (residenceScrollPane == null) {
			residenceScrollPane = new JScrollPane();
			residenceScrollPane.setViewportView(getResidenceTextArea());
			residenceScrollPane.setName("residenceScrollPane");
		}
		return residenceScrollPane;
	}
	private JTextArea getResidenceTextArea() {
		if (residenceTextArea == null) {
			residenceTextArea = new JTextArea();
			residenceTextArea.setName("residenceTextArea");
			residenceTextArea.setDocument(new FixedLengthDocument(5000));
		}
		return residenceTextArea;
	}
	private JLabel getLabel_8() {
		if (numberOfPeopleLabel == null) {
			numberOfPeopleLabel = new JLabel("Number of people to care for:");
			numberOfPeopleLabel.setLabelFor(getNumberOfPeopleTextfield());
			numberOfPeopleLabel.setName("numberOfPeopleLabel");
			numberOfPeopleLabel.setName("label");
		}
		return numberOfPeopleLabel;
	}
	private JLabel getNumberOfChildrenLabel() {
		if (numberOfChildrenLabel == null) {
			numberOfChildrenLabel = new JLabel("Number of children in school:");
			numberOfChildrenLabel.setLabelFor(getNumberOfChildrenTextfield());
			numberOfChildrenLabel.setName("numberOfChildrenLabel");
		}
		return numberOfChildrenLabel;
	}
	private JTextField getNumberOfChildrenTextfield() {
		if (numberOfChildrenTextfield == null) {
			numberOfChildrenTextfield = new NumericTextField(10, (DecimalFormat)DecimalFormat.getIntegerInstance());
			numberOfChildrenTextfield.setName(Member.NUMBER_CHILDREN_IN_SCHOOL);
		}
		return numberOfChildrenTextfield;
	}
	private JLabel getGroupLabel() {
		if (groupLabel == null) {
			groupLabel = new JLabel("Group:");
			groupLabel.setLabelFor(getGroupComboBox());
			groupLabel.setName("groupLabel");
		}
		return groupLabel;
	}
	protected MemberGroupComboBox getGroupComboBox() {
		if (groupComboBox == null) {
			groupComboBox = new MemberGroupComboBox();
			groupComboBox.setName("groupComboBox");
			groupComboBox.setModel(new EnumComboBoxModel(BOMemberGroup.create().readMemberGroups().toArray(), "<< Please select >>"));
			groupComboBox.enableAutocompletion();
		}
		return groupComboBox;
	}
	
	public static class MemberGroupComboBox extends EnumComboBox<MemberGroup> {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public String convertToString(MemberGroup enumValue) {
			if (enumValue != null) {
				return enumValue.getShortName() + " - " + enumValue.getName();
			}
			return "<< Please select >>";
		}
	}
	
	public static class GenderComboBox extends EnumComboBox<Gender> {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		
		@Override
		public String convertToString(Gender enumValue) {
			if (enumValue == Gender.M) {
				return "Male";
			} else if (enumValue == Gender.F) {
				return "Female";
			}
			return "<< Please select >>";
		}
	}
	
	public static class LevelOfEducationComboBox extends EnumComboBox<LevelOfEducation> {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public String convertToString(LevelOfEducation enumValue) {
			if (enumValue == LevelOfEducation.H) {
				return "Higher than secondary";
			} else if (enumValue == LevelOfEducation.P) {
				return "Primary";
			} else if (enumValue == LevelOfEducation.S) {
				return "Secondary";
			} else if (enumValue == LevelOfEducation.L) {
				return "Less than primary";
			}
			return "<< Please select >>";
		}
	}
	
	public static class MartialStatusComboBox extends EnumComboBox<MartialStatus> {
		
		private static final long serialVersionUID = 1L;

		@Override
		public String convertToString(MartialStatus enumValue) {
			if (enumValue == null) {
				return "<< Please select >>";
			}
			switch(enumValue) {
			case D: return "Separated";
			case M: return "Married";
			case P: return "Partnership";
			case S: return "Single";
			case W: return "Widow";
			}
			return "<< Please select >>";
		}
	}
	
	public static class HIVStatusComboBox extends EnumComboBox<HIVStatus> {
		
		private static final long serialVersionUID = 1L;

		@Override
		public String convertToString(HIVStatus enumValue) {
			if (enumValue == null) {
				return "<< Please select >>";
			}
			switch(enumValue) {
			case N: return "Negative";
			case P: return "Postive";
			case U: return "Unknown";
			}
			return "<< Please select >>";
		}
	}



	private JLabel getLblAdditionalInformation() {
		if (lblAdditionalInformation == null) {
			lblAdditionalInformation = new JLabel("Notes");
		}
		return lblAdditionalInformation;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getDescriptionTextArea());
		}
		return scrollPane;
	}
	private JTextArea getDescriptionTextArea() {
		if (descriptionTextArea == null) {
			descriptionTextArea = new JTextArea();
			descriptionTextArea.setWrapStyleWord(true);
			descriptionTextArea.setLineWrap(true);
			descriptionTextArea.setDocument(new FixedLengthDocument(5000));
		}
		return descriptionTextArea;
	}
	private JLabel getInactiveReasonLabel() {
		if (inactiveReasonLabel == null) {
			inactiveReasonLabel = new JLabel("Inactive Reason:");
		}
		return inactiveReasonLabel;
	}
	private JLabel getInactiveReasonTextLabel() {
		if (inactiveReasonTextLabel == null) {
			inactiveReasonTextLabel = new JLabel("Reason description:");
		}
		return inactiveReasonTextLabel;
	}
	private JScrollPane getInactiveReasonTextScrollPane() {
		if (inactiveReasonTextScrollPane == null) {
			inactiveReasonTextScrollPane = new JScrollPane();
			inactiveReasonTextScrollPane.setViewportView(getInactiveReasonTextArea());
		}
		return inactiveReasonTextScrollPane;
	}
	private JTextArea getInactiveReasonTextArea() {
		if (inactiveReasonTextArea == null) {
			inactiveReasonTextArea = new JTextArea();
			inactiveReasonTextArea.setLineWrap(true);
			inactiveReasonTextArea.setWrapStyleWord(true);
			inactiveReasonTextArea.setRows(3);
			inactiveReasonTextArea.setDocument(new FixedLengthDocument(5000));
			inactiveReasonTextArea.setName(Member.INACTIVE_REASON_TEXT);
		}
		return inactiveReasonTextArea;
	}
	
	
	private static class MemberInactiveReasonCombobox extends EnumComboBox<MemberInactiveReason> {
		
		public MemberInactiveReasonCombobox() {
			super(MemberInactiveReason.values(), true);
		}

		@Override
		public String convertToString(MemberInactiveReason enumValue) {
			if (enumValue == null) {
				return "<< Please select >>";
			}
			return enumValue.toString();
		}
	}
	
	private MemberInactiveReasonCombobox getInactiveReasonCombobox() {
		if (inactiveReasonCombobox == null) {
			inactiveReasonCombobox = new MemberInactiveReasonCombobox();
			inactiveReasonCombobox.setName(Member.INACTIVE_REASON);
			inactiveReasonCombobox.enableAutocompletion();
		}
		return inactiveReasonCombobox;
	}
	private JSeparator getInactiveSeparator() {
		if (inactiveSeparator == null) {
			inactiveSeparator = new JSeparator();
		}
		return inactiveSeparator;
	}

	private MDatePicker getBirtdatePanel() {
		if (birtdatePanel == null) {
			birtdatePanel = new MDatePicker();
			birtdatePanel.setName(Member.BIRTH_DATE);
		}
		return birtdatePanel;
	}
	private JLabel getHivStatusLabel() {
		if (hivStatusLabel == null) {
			hivStatusLabel = new JLabel("HIV Status:");
			hivStatusLabel.setLabelFor(getHivStatusComboBox());
		}
		return hivStatusLabel;
	}
	private HIVStatusComboBox getHivStatusComboBox() {
		if (hivStatusComboBox == null) {
			hivStatusComboBox = new HIVStatusComboBox();
			hivStatusComboBox.setName(Member.HIV_STATUS);
			hivStatusComboBox.setModel(new EnumComboBoxModel(HIVStatus.values(), "<< Please select >>"));
			hivStatusComboBox.enableAutocompletion();
		}
		return hivStatusComboBox;
	}
	private JLabel getMartialStatusLabel() {
		if (martialStatusLabel == null) {
			martialStatusLabel = new JLabel("Martial Status:");
			martialStatusLabel.setLabelFor(getMartialStatusComboBox());
		}
		return martialStatusLabel;
	}
	private MartialStatusComboBox getMartialStatusComboBox() {
		if (martialStatusComboBox == null) {
			martialStatusComboBox = new MartialStatusComboBox();
			martialStatusComboBox.setName(Member.MARTIAL_STATUS);
			martialStatusComboBox.setModel(new EnumComboBoxModel(MartialStatus.values(), "<< Please select >>"));
			martialStatusComboBox.enableAutocompletion();
		}
		return martialStatusComboBox;
	}
}
